package models

// Model
type AdminUser struct {
	ID          uint32      `json:"id" gorm:"primaryKey" example:"1"`
	Name        string      `json:"name"  example:"张三"`
	Phone       string      `json:"phone" gorm:"unique_index" example:"13245698745"`
	Password    string      `json:"password"`
	Status      int8        `json:"status"`
	CreatedTime uint64      `json:"created_time"`
	UpdatedTime uint64      `json:"updated_time"`
	AdminRoles  []AdminRole `json:"roles" gorm:"many2many:admin_user_role;association_autoupdate:false"`
}

func (AdminUser) TableName() string {
	return "admin_user"
}

type AdminRole struct {
	ID          uint32      `json:"id" gorm:"primaryKey"`
	Name        string      `json:"name"`
	Status      int8        `json:"status"`
	CreatedTime uint64      `json:"created_time"`
	UpdatedTime uint64      `json:"updated_time"`
	AdminAuths  []AdminAuth `json:"auths" gorm:"many2many:admin_role_auth;association_autoupdate:false"`
}

func (AdminRole) TableName() string {
	return "admin_role"
}

type AdminAuth struct {
	ID          uint32 `json:"id" gorm:"primaryKey"`
	Name        string `json:"name"`
	Type        int8   `json:"type"`
	Pid         uint32 `json:"pid"`
	ActionKey   string `json:"action_key"`
	Status      int8   `json:"status"`
	CreatedTime uint64 `json:"created_time"`
	UpdatedTime uint64 `json:"updated_time"`
}

func (AdminAuth) TableName() string {
	return "admin_auth"
}

type AdminDownload struct {
	ID          uint32    `json:"id" gorm:"primaryKey"`
	Name        string    `json:"name"`
	Url         string    `json:"url"`
	UserID      uint32    `json:"user_id"`
	User        AdminUser `json:"user" gorm:"foreignkey:UserID;association_autoupdate:false"`
	Status      int8      `json:"status"` // 0:已删除，1:处理中， 2:完成
	CreatedTime uint64    `json:"created_time"`
	UpdatedTime uint64    `json:"updated_time"`
}

func (AdminDownload) TableName() string {
	return "admin_download"
}
